/**
 * 
 */
package com.parktech.sun.utils.action;

/*
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
*/

public class MailSender {

//	private final static Logger LOG = LogManager.getLogger(MailSender.class);
	
/*	public boolean send(String toMmail, String title, String content) {
		try {
			SmtpConfig smtp = getSmtpConfig();
			MailUtil mail = new MailUtil();
			mail.send(smtp, toMmail, title, content);
		} catch (Exception e) {
//			LOG.fatal("发送邮件失败...", e);
			return false;
		}
		return true;
	}*/

    public boolean send(String toMmail, String title, String content, String senderName,String senderPassword) {
		try {
			SmtpConfig smtp = getSmtpConfig();
			MailUtil mail = new MailUtil();
            if(senderName!=null && senderName.trim().equals(smtp.getUserName2()))
            {
                mail.send(smtp, toMmail, title, content, senderName, senderPassword,smtp.getSender2DepartName());
            }
            else
            {
               mail.send(smtp, toMmail, title, content, senderName, senderPassword,smtp.getSender1DepartName());
            }

		} catch (Exception e) {
//			LOG.fatal("发送邮件失败...", e);
			return false;
		}
		return true;
	}


	public SmtpConfig getSmtpConfig() {
		
		SmtpConfig smtp = new SmtpConfig();
		
		int port=Integer.parseInt(ConfigUtil.getConfigValue("port"));
		smtp.setPort(port);
		smtp.setDomain(ConfigUtil.getConfigValue("domain"));
		smtp.setUser(ConfigUtil.getConfigValue("user"));
		smtp.setHost(ConfigUtil.getConfigValue("host"));
		smtp.setPassword(ConfigUtil.getConfigValue("password"));

        smtp.setUserName2(ConfigUtil.getConfigValue("userName2"));
        smtp.setPassword2(ConfigUtil.getConfigValue("password2"));

        smtp.setSender1DepartName("sender1DepartName");
        smtp.setSender2DepartName("sender2DepartName");

		return smtp;
	}

}
